Soy nuevo en JavaScript. Estoy tratando de imprimir una matriz usando una función document.getElementById . Recibo un error Uncaught TypeError: Cannot set properties of null (setting 'innerHTML') at call.html:10:58
<!DOCTYPE html> <html> <head> <title>My information</title> <body> <h1>My name is Luffy</h1> <p>I am a software developer</p> <script> const programmingLanguage = ["Python", "Java","C"]; document.getElementById("program").innerHTML=programmingLanguage; </script> </body> </head> </html>por favor ayúdame donde me equivoqué
El problema es que está tratando de obtener un elemento que tiene el programa de identificación, pero no hay ningún elemento que tenga la identificación como program .
Puede crear un elemento con program id. esto resolverá el error.
<!DOCTYPE html> <html> <head> <title>My information</title> <body> <h1>My name is Luffy</h1> <p>I am a software developer</p> <p id="program"></p> <script> const programmingLanguage = ["Python", "Java","C"]; document.getElementById("program").innerHTML=programmingLanguage; </script> </body> </head> </html>